home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Comm / net / SLH.lha / SLH / slh next >
Text File  |  2004-08-08  |  7KB  |  225 lines

  1. /* Samba's little Helper slh.rexx v0.3 */
  2.  
  3. signal on halt
  4. signal on break_c
  5. options results
  6.  
  7. call Init
  8. call createApp
  9.  
  10. call handleApp
  11.  
  12. /***********************************************************************/
  13. Init: procedure expose global.
  14.  l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
  15.  if AddLibrary("rexxsupport.library","rxmui.library")~=0 then exit
  16.  if AddLibrary("rxasl.library")~=0 then exit
  17.  
  18.  call ReadToolTypes("SLH","ttyp")
  19.  
  20.  global.path = "Samba:bin"
  21.  global.ipcounter=0
  22.  do a = 0 to ttyp.num - 1
  23.   if ttyp.a.Active = 1 then do
  24.    if upper(ttyp.a) = "SAMBABINPATH" then global.path = ttyp.a.Value
  25.    else if upper(ttyp.a) = "ADDIP" then do
  26.     global.ipcounter = global.ipcounter+1
  27.     nr = global.ipcounter
  28.     global.ipnumber.nr = ttyp.a.Value
  29.     global.ipnames.nr = ttyp.a.Value
  30.    end
  31.    else do
  32.     pa = upper(ttyp.a)
  33.     if index(ttyp.a,"/") > 0 then global.pass.pa = ttyp.a.Value
  34.    end
  35.   end
  36.  end
  37.  
  38.  call SetRxMUIStack(64000)
  39. return
  40. /***********************************************************************/
  41. HandleApp: procedure expose global.
  42.     ctrl_c=2**12
  43.     do forever
  44.         call NewHandle("app","h",ctrl_c)
  45.         if and(h.signals,ctrl_c)>0 then exit
  46.         if h.EventFlag then
  47.             select
  48.                 when h.event="QUIT" then exit
  49.                 otherwise interpret h.event
  50.             end
  51.         end
  52.     end
  53. /***********************************************************************/
  54. createApp: procedure expose global.
  55.     app.Title="SLH"
  56.     app.Version="$VER: 0.3 Samba's Little Helper (08.08.2004)"
  57.     app.Copyright="No Copyright by Robin"
  58.     app.Author="Robin Hueskes robin@amiganiac.net"
  59.     app.Description="Samba's Little Helper"
  60.     app.Base="SLH"
  61.  
  62.     app.menustrip="strip"
  63.      strip.class="Menustrip"
  64.      strip.0="mproject"
  65.       mproject.Title="Project"
  66.       mproject.class="menu"
  67.        mproject.0=menuitem("mabout","?\About...")
  68.        mproject.1=menuitem("maboutrxmui","About RxMUI...")
  69.        mproject.2=menuitem("maboutmui","!\About MUI...")
  70.        mproject.3=menuitem("","BAR")
  71.        mproject.4=menuitem("mhide","I\Iconify")
  72.        mproject.5=menuitem("","BAR")
  73.        mproject.6=menuitem("mquit","Q\Quit")
  74.      app.SubWindow.0="win"
  75.       win.class="Window"
  76.       win.title="Samba's Little Helper"
  77.       win.ID="PWIN"
  78.       win.Contents="dgroup"
  79.        dgroup.class="group"
  80.        dgroup.0="iv"
  81.         iv.class = "NListView"
  82.         iv.list = "iw"
  83.         iw.class = "nlist"
  84.         iw.title = "Server|Domain|IP|Share|Task"
  85.         iw.format = ",,,,"
  86.        dgroup.1=button("c_but1","_Scan")
  87.     call NewObj("APPLICATION","APP")
  88.  
  89.     call Notify("win","CloseRequest",1,"app","ReturnID","QUIT")
  90.     call Notify("mabout","menutrigger","Everytime","app","about","win")
  91.     call Notify("maboutrxmui","menutrigger","everytime","app","aboutrxmui","win")
  92.     call Notify("maboutmui","menutrigger","everytime","app","aboutmui","win")
  93.     call Notify("mhide","menutrigger","everytime","app","set","iconified",1)
  94.     call Notify("mquit","menutrigger","everytime","app","ReturnID","QUIT")
  95.     call Notify("c_but1","pressed",0,"app","Return","call MD")
  96.     call Notify("iw","DoubleClick","EveryTime","app","Return","call CD()")
  97. call MD()
  98.     call set("win","open",1)
  99.  
  100.     return
  101. /***********************************************************************/
  102.  
  103. CD: procedure expose global.
  104.  call DoMethod("iw","GetEntry","Active","line")
  105.  parse var line server"|"domain"|"ip"|"share"|"tnr
  106.  if datatype(tnr,"N") then address command "break c" tnr
  107.  else do
  108.   parse var tnr suser":"spass
  109.   if tnr = "Not mounted" then address command "run >nil: smbfs volume="server"_"share "workgroup="domain "service=//"server"/"share
  110.   else address command "run >nil: smbfs user="suser" password="spass" volume="server"_"share "workgroup="domain "service=//"server"/"share
  111.  end
  112.  address command "wait"
  113.  call MD()
  114. return
  115.  
  116. MD: procedure expose global.
  117.  call DoMethod("iw","Clear")
  118. path=global.path
  119.  
  120. tmp = rmh_GetUniqueID()
  121. tmp = "pipe:slh_"||tmp
  122. com = "status >"tmp
  123.  
  124. address command com
  125. if open('temp',tmp,'R') then do
  126.  do while ~EOF('temp')
  127.   nix = readln('temp')
  128.   parse var nix "Process " processnr": Loaded as command: " comline
  129.  
  130.   if index(upper(comline),"SMBFS") > 0 then do
  131.    parse var comline smbfs" '//"sharename"'"
  132.    activeshare.sharename = processnr
  133.   end
  134.  end
  135. end
  136. close('temp')
  137. tmp = rmh_GetUniqueID()
  138. tmp = "pipe:slh_"||tmp
  139. com = rmh_addpart(path,'nmblookup')
  140. com = com "-d 0 -T * >"||tmp
  141.  
  142. address command com
  143. if open('temp',tmp,'R') then do
  144.  ipcount = global.ipcounter
  145.  if ipcount > 0 then do a = 1 to ipcount
  146.   ipnr.a = global.ipnumber.a
  147.   ipname.a = global.ipnames.a
  148.  end
  149.  do while ~EOF('temp')
  150.   nix = readln('temp')
  151.   if index(nix,"<00>") > 0 then do
  152.    parse var nix name", "ip " " info
  153.    ipcount = ipcount + 1
  154.    ipnr.ipcount = ip
  155.    ipname.ipcount = name
  156.   end
  157.  end
  158.  call close('temp')
  159.  tmp = rmh_GetUniqueID()
  160.  tmp = "pipe:slh_"||tmp
  161.  com = rmh_addpart(path,'nmblookup')
  162.  com = com "-d 0 -T -M - >"||tmp
  163.  address command com
  164.  if open('temp',tmp,'R') then do
  165.   do while ~EOF('temp')
  166.    nix = readln('temp')
  167.    if index(nix,"<01>") > 0 then do
  168.     parse var nix name", "ip " " info
  169.     ipcount = ipcount + 1
  170.     ipnr.ipcount = ip
  171.     ipname.ipcount = name
  172.    end
  173.   end
  174.   call close('temp')
  175.  end
  176.  if ipcount > 0 then do
  177.   do a = 1 to ipcount
  178.    mode = 0
  179.    oldmode = 0
  180.    tmp = rmh_GetUniqueID()
  181.    tmp = "pipe:slh_"||tmp
  182.    com = rmh_addpart(path,'smbclient')
  183.    com = com "-N -L" ipnr.a ">"||tmp
  184.    address command com
  185.    if open('temp',tmp,'R') then do
  186.     do while ~EOF('temp')
  187.      nix = readln('temp')
  188.      if index(upper(nix),"DOMAIN") = 1 then do
  189.       parse var nix "Domain=["info_domain"] OS=["info_os"] Server=["info_server"]"
  190.      end
  191.      else if index(upper(strip(compress(nix))),"SHARENAMETYPECOMMENT") > 0 then mode=1
  192.      else if index(upper(strip(compress(nix))),"SERVERCOMMENT") > 0 then mode=2
  193.      else if index(upper(strip(compress(nix))),"WORKGROUPMASTER") > 0 then mode=3
  194.      if oldmode ~= mode then do
  195.       nix = readln('temp')
  196.       nix = readln('temp')
  197.       oldmode = mode
  198.      end
  199.      if mode = 1 then do
  200.       parse var nix info_share info_type info_comment
  201.       info_share = strip(info_share)
  202.       info_share = strip(info_share,'L',x2c(09))
  203.       info_type = strip(info_type)
  204.       info_comment = strip(info_comment)
  205.       if upper(info_type) = 'DISK' then do
  206.        sn = ipname.a"/"info_share
  207.        su = upper(sn)
  208.        tnr = global.pass.su
  209.        if index(tnr,"GLOBAL.PASS.") > 0 then tnr = "Not mounted"
  210.        ipn = ipname.a
  211.        if datatype(activeshare.sn,"N") then do
  212.         tnr = activeshare.sn
  213.         ipn = ParseText("%b"ipname.a)
  214.        end
  215.        ili = ipn"|"info_domain"|"ipnr.a"|"info_share"|"tnr
  216.        call DoMethod("iw","INSERT",ili,"Sorted")
  217.       end
  218.      end
  219.     end
  220.     call close('temp')
  221.    end
  222.   end
  223.  end
  224. end
  225. return